package com.wandar.gc.config;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
 * 
 * @author huangxm
 * 
 */
public enum TypeEnum {

	DATE("Date", "DATE", "java.util.Date", "DATE"), 
	TIMESTAMP("Date","TIMESTAMP", "java.util.Date", "DATE"), 
	TIME("Date", "TIME","java.util.Date", "DATE"), 
	DATETIME("Date", "DATETIME","java.util.Date", "DATE"),
	VARCHAR("String", "VARCHAR", "java.lang.String", "VARCHAR"), 
	CHAR("String","CHAR", "java.lang.String", "CHAR"),
	BIGINT("Long", "BIGINT", "java.lang.Long", "BIGINT"), 
	BIT("Boolean", "BIT","java.lang.Boolean", "BIT"),
	DECIMAL("BigDecimal", "DECIMAL", "java.math.BigDecimal", "DECIMAL"), 
	DOUBLE("Double", "DOUBLE", "java.lang.Double", "DOUBLE"), 
	REAL("Float","REAL", "java.lang.Float", "REAL"), 
	INT("Integer", "INT","java.lang.Integer", "INTEGER"),
	SMALLINT("Short", "SMALLINT", "java.lang.Short", "SMALLINT"),
	TINYINT("Byte", "TINYINT", "java.lang.Byte", "TINYINT"), 
	UNKNOWN("String","UNKNOWN", "java.lang.String", "VARCHAR");

	private final String type;
	private final String jdbcType;
	private final String sqlType;
	private final String javaType;

	/**
	 * @param code
	 * @param message
	 */
	private TypeEnum(String type, String sqlType, String javaType,
			String jdbcType) {
		this.type = type;
		this.sqlType = sqlType;
		this.javaType = javaType;
		this.jdbcType = jdbcType;
	}

	public String getType() {
		return type;
	}

	public String getSqlType() {
		return sqlType;
	}

	public String getJavaType() {
		return javaType;
	}

	public String getJdbcType() {
		return jdbcType;
	}

	/**
	 * 
	 * @param sqlType
	 * @return
	 */
	public static TypeEnum getBySqlType(String sqlType) {
		for (TypeEnum _enum : values()) {
			if (StringUtils.equals(_enum.getSqlType(), sqlType)) {
				return _enum;
			}
		}
		return TypeEnum.getBySqlType(TypeEnum.UNKNOWN.sqlType);
	}

	/**
	 * 获取全部枚举
	 * 
	 * @return
	 */
	public List<TypeEnum> getAllEnum() {
		List<TypeEnum> list = new ArrayList<TypeEnum>();
		for (TypeEnum _enum : values()) {
			list.add(_enum);
		}
		return list;
	}

	public List<String> getAllTavaType() {
		List<String> list = new ArrayList<String>();
		for (TypeEnum _enum : values()) {
			list.add(_enum.getJavaType());
		}
		return list;
	}

	/**
	 * @return
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this,
				ToStringStyle.SHORT_PREFIX_STYLE);
	}

	public static void main(String args[]) {

		System.out.println(TypeEnum.getBySqlType("BIGINT").javaType);

	}
}